-
Couldn't load subscription status.
- Fork 1.5k
Fix #14074 FP constParameterReference reported for std::array object when non-const pointer to internal data is returned #7890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
lib/valueflow.cpp
Outdated
| const Library::Container* library = getLibraryContainer(tok->tokAt(-2)->astOperand1()); | ||
| const Library::Container::Yield y = library->getYield(tok->strAt(-1)); | ||
| if (y == Library::Container::Yield::AT_INDEX || y == Library::Container::Yield::ITEM) { | ||
| if (contains({Library::Container::Yield::AT_INDEX, Library::Container::Yield::ITEM, Library::Container::Yield::BUFFER, Library::Container::Yield::BUFFER_NT}, y)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct, The buffer returns a pointer not a reference so it should not be used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is called getLifetimeTokens() though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its get the lifetime of a reference. Thats why the it only follows the function that return references(see here). Its similar to followReferences, but different as it will get the parent lifetime of a reference as well.
Originally, it was called getLifetimeVariable(and there is still an overload for this), but was renamed to getLifetimeTokens so it can handle expressions and multiple lifetimes.
The lifetime of pointers are set in valueflow in the token. For pointer to containers data() method, we set the lifetime here:
Line 3237 in 5f301d3
| master.errorPath.emplace_back(parent->tokAt(2), "Pointer to container is created here."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no mention of pointers or references anywhere regarding those functions. But apparently the issue was in checkConstVariable().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that is my fault entirely since I wrote and named this function originally.
|



No description provided.